//
//  zucexinxiViewController.m
//  BAOASystem
//
//  Created by michael on 2018/2/1.
//  Copyright © 2018年 czd. All rights reserved.
//
#import <CommonCrypto/CommonDigest.h>
#import "qiyezuceViewController.h"
#import "JJLabel.h"
#import "zucexinxiViewController.h"
#import "OALoginViewController.h"
#import "OALoginViewController.h"
@interface zucexinxiViewController ()

@end

@implementation zucexinxiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
       NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 
[self.navigationController.navigationBar setTitleTextAttributes:attributes];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0a62ea"];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.title = NSLocalizedString(@"注册信息", nil);
//      self.view.userInteractionEnabled=NO;
//    self.view.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];

       _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,KScreenHeight-kTopHeight) style:UITableViewStylePlain];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView];


  UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"]style:UIBarButtonItemStylePlain target:self action:@selector(buttonClick)];
 self.navigationItem.leftBarButtonItem = item1;
    // Do any additional setup after loading the view.
}
- (void)buttonClick{

      UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

        OALoginViewController * loginVC = [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
        UINavigationController * navVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
    self.view.window.rootViewController = navVC;
        loginVC.navigationController.navigationBar.hidden = YES;
}
- (void)endediting{
NSString *idstring=[_loginnameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (idstring.length>0) {
     NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>administrator</userName><password>b628e2c3b78ef9bf269c489b35176e48</password><website>%@</website><language>%@</language><type>%@</type></header><body><user><username>%@</username></user></body></message>",website,language,BAtype,idstring];
    bodyStr= [bodyStr URLEncodedString];

 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bcheckUserName];

 [HttpTools requestWithURL:path arrays:array method:@"checkUserName" success:^(id JSON) {
    [MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"%@",JSON);
//[self.view make321Toast:JSON[@"msg"]];
if ([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"])
{
  [self.view makeToast:JSON[@"msg"]];

_type = @"no";
}else{

_type = @"ok";

}
    } failure:^(NSError *error) {
      [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];


}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  8;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"dic"];
if(indexPath.row ==0){
static NSString *cellid0 = @"cell0";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid0];
     if (!cell) {
  cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid0];
      cell.selectionStyle = UITableViewCellSelectionStyleNone;

    UILabel *label0 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-20, 30)];
    label0.textColor = [UIColor colorWithHexString:@"0a62ea"];
    label0.text = NSLocalizedString(@"用户基本信息", nil);
        [cell.contentView addSubview:label0];

  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, label0.bottom,KScreenWidth-20, 20)];
  
label.textColor = [UIColor colorWithHexString:@"484848"];

     NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"注册信息-登录名", nil)];
     
     NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label.attributedText = attrStr;

    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
        _loginnameField = [[zhucetextfield alloc]init];
              _loginnameField.delegate = self;
 _loginnameField.frame = CGRectMake(10, label.bottom+10, (KScreenWidth-20), 40);
 _loginnameField.placeholder = NSLocalizedString(@"6-20位的数字或字母", nil);
  [_loginnameField addTarget:self action:@selector(endediting) forControlEvents:UIControlEventEditingDidEnd];// 可在自定义selector处
//    yhmtring = 123123;
//    qiyenamestring = 123;
//    ckmimatring = 123123;
//    qqstring = 123123@qq.com;
//    phonestring = 18242364113;
//    mimatring = 123123;
//    namestring = 123;
if (dic) {
    _loginnameField.text = dic[@"yhmtring"];
}
             _loginnameField.keyboardType = UIKeyboardTypeASCIICapable;
             [cell.contentView addSubview:_loginnameField];

     }
return cell;
}if(indexPath.row ==1){
static NSString *cellid1 = @"cell1";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid1];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     if (!cell) {
  cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid1];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  
label.textColor = [UIColor colorWithHexString:@"484848"];

          NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"注册信息-密码", nil)];
     NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label.attributedText = attrStr;

    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    _mimaField = [[zhucetextfield alloc]init];
     _mimaField.delegate = self;
     [_mimaField setSecureTextEntry:YES];

 _mimaField.placeholder = NSLocalizedString(@"6-20位的数字或字母", nil);
_mimaField.keyboardType = UIKeyboardTypeASCIICapable;
if (dic) {
    _mimaField.text = dic[@"mimatring"];
}
 _mimaField.frame = CGRectMake(10, label.bottom+10, (KScreenWidth-20), 40);
             [cell.contentView addSubview:_mimaField];
     }
return cell;
}if(indexPath.row ==2){
static NSString *cellid2 = @"cell2";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid2];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     if (!cell) {
  cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid2];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];

         NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"注册信息-确认密码", nil)];
     NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label.attributedText = attrStr;

    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    _checkmimaField = [[zhucetextfield alloc]init];
     _checkmimaField.delegate = self;
     [_checkmimaField setSecureTextEntry:YES];

 _checkmimaField.placeholder = NSLocalizedString(@"6-20位的数字或字母", nil);
_checkmimaField.keyboardType = UIKeyboardTypeASCIICapable;
if (dic) {
    _checkmimaField.text = dic[@"ckmimatring"];
}
 _checkmimaField.frame = CGRectMake(10, label.bottom+10, (KScreenWidth-20), 40);
             [cell.contentView addSubview:_checkmimaField];
     }
return cell;
}if(indexPath.row ==3){
static NSString *cellid3 = @"cell3";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid3];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     if (!cell) {
  cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid3];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];

       NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"注册信息-邮箱", nil)];
     NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label.attributedText = attrStr;

    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    _emailField = [[zhucetextfield alloc]init];
     _emailField.delegate = self;

// _checkmimaField.placeholder = NSLocalizedString(@"6-20位的数字或字母", nil);
_emailField.keyboardType = UIKeyboardTypeASCIICapable;
if (dic) {
    _emailField.text = dic[@"qqstring"];
}
 _emailField.frame = CGRectMake(10, label.bottom+10, (KScreenWidth-20), 40);
             [cell.contentView addSubview:_emailField];
     }
return cell;
}if(indexPath.row ==4){
static NSString *cellid4 = @"cell4";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid4];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     if (!cell) {
  cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid4];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];

    
            NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"注册信息-手机号码", nil)];
     NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label.attributedText = attrStr;

    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    _phoneField = [[zhucetextfield alloc]init];
     _phoneField.delegate = self;
//     [_phoneField setSecureTextEntry:YES];

// _checkmimaField.placeholder = NSLocalizedString(@"6-20位的数字或字母", nil);
_phoneField.keyboardType = UIKeyboardTypeASCIICapable;
if (dic) {
    _phoneField.text = dic[@"phonestring"];
}
 _phoneField.frame = CGRectMake(10, label.bottom+10, (KScreenWidth-20), 40);
             [cell.contentView addSubview:_phoneField];
     }
return cell;
}if(indexPath.row ==5){
static NSString *cellid5 = @"cell5";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid5];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     if (!cell) {
  cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid5];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];

      NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"注册信息-姓名", nil)];
     NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    _nameField = [[zhucetextfield alloc]init];
     _nameField.delegate = self;
if (dic) {
    _nameField.text = dic[@"namestring"];
}
// _checkmimaField.placeholder = NSLocalizedString(@"6-20位的数字或字母", nil);
//_phoneField.keyboardType = UIKeyboardTypeASCIICapable;

 _nameField.frame = CGRectMake(10, label.bottom+10, (KScreenWidth-150), 40);
             [cell.contentView addSubview:_nameField];
//              _sexbox = [[jiaotongbox alloc]init];
          _sexbox = [jiaotongbox checkBoxFootView];
if (dic) {
   _sexbox.seltag = [dic[@"sexstring"] integerValue];
}else{

        _sexbox.seltag = 0;

}
//              _xmField.delegate = self;
 _sexbox.frame = CGRectMake(_nameField.right+10, _nameField.top, 130, 40);
             [cell.contentView addSubview:_sexbox];
     }
return cell;
}if(indexPath.row ==6){
static NSString *cellid6 = @"cell6";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid6];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     if (!cell) {
  cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid6];
   UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];

    NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"注册信息-企业名称", nil)];
     NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    _qiyenameField = [[zhucetextfield alloc]init];
     _qiyenameField.delegate = self;
     

// _checkmimaField.placeholder = NSLocalizedString(@"6-20位的数字或字母", nil);
//_qiyenameField.keyboardType = UIKeyboardTypeASCIICapable;
if (dic) {
    _qiyenameField.text = dic[@"qiyenamestring"];
}
 _qiyenameField.frame = CGRectMake(10, label.bottom+10, (KScreenWidth-20), 40);
             [cell.contentView addSubview:_qiyenameField];
     }
return cell;
}else{
static NSString *cellid7 = @"cell7";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid7];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     if (!cell) {
  cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid7];
 _button= [UIButton buttonWithType:UIButtonTypeCustom];
 [_button setTitle:NSLocalizedString(@"我已阅读,并同意浙江省贸易促进网用户协议", nil) forState:UIControlStateNormal];
     _button.titleLabel.font = [UIFont systemFontOfSize: 13.0];

  [_button setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [_button setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
    _button.frame = CGRectMake(10, 0, KScreenWidth-40, 30);
            [_button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft
                                    imageTitleSpace:5];
        [_button setTitleColor:[UIColor colorWithHexString:@"0aa0f6"]forState:UIControlStateNormal];
                [_button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];

    [cell.contentView addSubview:_button];
      UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
      button2.frame = CGRectMake(20, _button.bottom+10, (KScreenWidth-60)/2, 40);
          button2.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

    [button2 setTitle:NSLocalizedString(@"注册信息-下一步", nil) forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize: 14.0];
          [button2 setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
//        button2.layer.cornerRadius = button.height/2;
                [button2 addTarget:self action:@selector(action2) forControlEvents:UIControlEventTouchUpInside];

            [cell.contentView addSubview:button2];
             UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
      button3.frame = CGRectMake(button2.right+20, _button.bottom+10, (KScreenWidth-60)/2, 40);
          button3.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

    [button3 setTitle:NSLocalizedString(@"注册", nil) forState:UIControlStateNormal];
    button3.titleLabel.font = [UIFont systemFontOfSize: 14.0];
          [button3 setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
//        button2.layer.cornerRadius = button.height/2;
                [button3 addTarget:self action:@selector(action3) forControlEvents:UIControlEventTouchUpInside];

            [cell.contentView addSubview:button3];

     }
return cell;
}


}
- (void)action:(UIButton *)button{
button.selected = !button.selected;
}
-   (void)action3{
NSString *yhmtring=[_loginnameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *mimatring=[_mimaField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *ckmimatring=[_checkmimaField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *qqstring=[_emailField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *phonestring=[_phoneField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *namestring=[_nameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *qiyenamestring=[_qiyenameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (!_button.selected) {
     [self.view makeToast:NSLocalizedString(@"注册信息-请勾选同意协议", nil)];
}else if ([_type isEqualToString:@"no"]){
     [self.view makeToast:NSLocalizedString(@"用户名存在", nil)];
}
else if ([yhmtring isEqualToString:@""]|| yhmtring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-用户名为空", nil)];
}else if ([mimatring isEqualToString:@""]|| mimatring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-密码为空", nil)];
}else if ([ckmimatring isEqualToString:@""]|| ckmimatring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-确认密码为空", nil)];
}else if (yhmtring.length<6||yhmtring.length>20){
     [self.view makeToast:NSLocalizedString(@"注册信息-用户名不规范", nil)];
}else if (mimatring.length<6||mimatring.length>20){
     [self.view makeToast:NSLocalizedString(@"注册信息-密码不规范", nil)];
}else if (ckmimatring.length<6||ckmimatring.length>20){
     [self.view makeToast:NSLocalizedString(@"注册信息-确认密码不规范", nil)];
}else if (![ckmimatring isEqualToString:mimatring]){
     [self.view makeToast:NSLocalizedString(@"注册信息-密码不一致", nil)];
}else if ([qqstring isEqualToString:@""]|| qqstring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-邮箱为空", nil)];
}else if (![httpTool isValidateEmail:qqstring]){
     [self.view makeToast:NSLocalizedString(@"注册信息-邮箱不规范", nil)];
}
else if ([phonestring isEqualToString:@""]|| phonestring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-手机为空", nil)];
}
else if (![httpTool checkTelNumber:phonestring]){
     [self.view makeToast:NSLocalizedString(@"注册信息-手机不规范", nil)];
}
else if ([namestring isEqualToString:@""]|| namestring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-姓名为空", nil)];
}else if ([qiyenamestring isEqualToString:@""]|| qiyenamestring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-公司名称为空", nil)];
}else{

//NSString *bodyStr = @"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>administrator</userName><password>b628e2c3b78ef9bf269c489b35176e48</password><website>1</website><language>0</language><type>1</type></header><body><user><username>Jessica</username><password>12345678</password><email>836863330@qq.com</email><phone>18258427692</phone><name>杰西卡</name><englishName>Jessica</englishName><sex>0</sex><nickname>飞软</nickname><nicknameEn>flysoft</nicknameEn></user></body></message>";
          NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
   NSString *password = mimatring;
mimatring = [ self md5:mimatring];
NSString *bodyStr = [NSString stringWithFormat: @"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>administrator</userName><password>b628e2c3b78ef9bf269c489b35176e48</password><website>%@</website><language>%@</language><type>%@</type></header><body><user><username>%@</username><password>%@</password><email>%@</email><phone>%@</phone><name>%@</name><englishName>%@</englishName><sex>%@</sex><nickname>%@</nickname><nicknameEn>%@</nicknameEn><cpbccontent>0</cpbccontent><pscode>%@</pscode></user></body></message>",website,language,BAtype,yhmtring,mimatring,qqstring,phonestring,namestring,namestring,_sexbox.orderString,qiyenamestring,qiyenamestring,password];
    bodyStr= [bodyStr URLEncodedString];
 NSArray * array = @[@{@"arg0":bodyStr}];
    NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bSaveRegister];
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];

  [HttpTools requestWithURL:path arrays:array method:@"SaveRegister" success:^(id JSON) {
    [MBProgressHUD hideHUDForView:self.view animated:YES];
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];

    [defaults removeObjectForKey:@"dic"];
    NSLog(@"%@",JSON);
         [self.view makeToast:JSON[@"msg"]];
         if ([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"]) {
[self performSelector: @selector(popaction) withObject: nil afterDelay:1.0f];

}

      
    } failure:^(NSError *error) {
      [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];
}


}
- (void)popaction{
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];

    [defaults removeObjectForKey:@"dic"];
//[self.navigationController popViewControllerAnimated:YES];
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

        OALoginViewController * loginVC = [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
        UINavigationController * navVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
    self.view.window.rootViewController = navVC;
        loginVC.navigationController.navigationBar.hidden = YES;

}
- (void)action2
{NSString *yhmtring=[_loginnameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *mimatring=[_mimaField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *ckmimatring=[_checkmimaField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *qqstring=[_emailField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *phonestring=[_phoneField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *namestring=[_nameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *qiyenamestring=[_qiyenameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (!_button.selected) {
     [self.view makeToast:NSLocalizedString(@"注册信息-请勾选同意协议", nil)];
}else if ([_type isEqualToString:@"no"]){
     [self.view makeToast:NSLocalizedString(@"用户名存在", nil)];
}
else if ([yhmtring isEqualToString:@""]|| yhmtring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-用户名为空", nil)];
}else if ([mimatring isEqualToString:@""]|| mimatring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-密码为空", nil)];
}else if ([ckmimatring isEqualToString:@""]|| ckmimatring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-确认密码为空", nil)];
}else if (yhmtring.length<6||yhmtring.length>20){
     [self.view makeToast:NSLocalizedString(@"注册信息-用户名不规范", nil)];
}else if (mimatring.length<6||mimatring.length>20){
     [self.view makeToast:NSLocalizedString(@"注册信息-密码不规范", nil)];
}else if (ckmimatring.length<6||ckmimatring.length>20){
     [self.view makeToast:NSLocalizedString(@"注册信息-确认密码不规范", nil)];
}else if (![ckmimatring isEqualToString:mimatring]){
     [self.view makeToast:NSLocalizedString(@"注册信息-密码不一致", nil)];
}else if ([qqstring isEqualToString:@""]|| qqstring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-邮箱为空", nil)];
}else if (![httpTool isValidateEmail:qqstring]){
     [self.view makeToast:NSLocalizedString(@"注册信息-邮箱不规范", nil)];
}
else if ([phonestring isEqualToString:@""]|| phonestring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-手机为空", nil)];
}
else if (![httpTool checkTelNumber:phonestring]){
     [self.view makeToast:NSLocalizedString(@"注册信息-手机不规范", nil)];
}
else if ([namestring isEqualToString:@""]|| namestring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-姓名为空", nil)];
}else if ([qiyenamestring isEqualToString:@""]|| qiyenamestring.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-公司名称为空", nil)];
}else{

    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:yhmtring forKey:@"yhmtring"];
[dic setObject:mimatring forKey:@"mimatring"];
[dic setObject:ckmimatring forKey:@"ckmimatring"];
[dic setObject:qqstring forKey:@"qqstring"];
[dic setObject:phonestring forKey:@"phonestring"];
[dic setObject:namestring forKey:@"namestring"];
[dic setObject:qiyenamestring forKey:@"qiyenamestring"];
[dic setObject:_sexbox.orderString forKey:@"sexstring"];
NSDictionary *dict = dic;
NSLog(@"%@",dict);
 [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"dic"];
qiyezuceViewController *vc = [[qiyezuceViewController alloc]init];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}

}
- (NSString *)md5:(NSString *)str
{
    const char *cStr = [str UTF8String];
    unsigned char result[16];
    CC_MD5(cStr, (CC_LONG)strlen(cStr), result); // This is the md5 call
    return [NSString stringWithFormat:
            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            result[0], result[1], result[2], result[3],
            result[4], result[5], result[6], result[7],
            result[8], result[9], result[10], result[11],
            result[12], result[13], result[14], result[15]
            ];
}
-(NSString *)URLEncodedString:(NSString *)str
{
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)str,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));
    
    return encodedString;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0){
return 90+10+5;
}if (indexPath.row == 7){
return 80+10;
}else{
return 60+10+5;
}


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
